package com.yksj.healthtalk.ui.chatting;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.app.AppData;
import com.yksj.healthtalk.ui.app.HTalkApplication;
import com.yksj.healthtalk.ui.chatting.InviteAttentionActivity.FriendsListAdapter;
import com.yksj.healthtalk.ui.chatting.InviteAttentionActivity.InviteFriendListener;
import com.yksj.healthtalk.ui.chatting.InviteAttentionActivity.ViewHolder;

/**
 * 
 * 邀请已经关注的人
 * @author zhao
 */
public class InviteAtationedFragment extends Fragment implements InviteFriendListener{
	
	ListView mListView;
	FriendsListAdapter mAdapter;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.invite_listview_layout, null);
		mListView = (ListView)view.findViewById(android.R.id.list);
		mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				ViewHolder holder = (ViewHolder)view.getTag();
				boolean  isChecked = holder.chooseBox.isChecked();
				CustomerInfoEntity entity = mAdapter.getItem(position);
				String userid = entity.getId();
				mAdapter.onChoose(userid,!isChecked);
				holder.chooseBox.setChecked(!isChecked);
			}
		});
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		mAdapter = new FriendsListAdapter(getLayoutInflater(savedInstanceState),getActivity());
		mListView.setAdapter(mAdapter);
		AppData appData = HTalkApplication.getAppData();
		mAdapter.onDataChange(appData.getInterestFriendList());
	}

	@Override
	public List<String> onInvite() {
		return new ArrayList<String>(mAdapter.mChoosedMap.keySet());
	}
}
